
from moviepy.editor import AudioFileClip

my_audio = AudioFileClip("example.mp4")
my_audio.write_audiofile("example.wav")


'''
from paddlespeech.cli.asr.infer import ASRExecutor
asr = ASRExecutor()
result = asr(audio_file="example.wav",force_yes=True)
print(result)
from paddlespeech.cli.text.infer import TextExecutor
text_punc = TextExecutor()
result = text_punc(text=result)
print(result)

import numpy as np
import librosa
audio, freq = librosa.load("example.wav")
time = np.arange(0, len(audio)) / freq

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(time, audio)
ax.set(xlabel='time (s)', ylabel='amplitude',
       title='Audio Signal')
plt.savefig("example.png")
exit()

'''


from paddleocr import PaddleOCR, draw_ocr

# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch")  # need to run only once to download and load model into memory
img_path = './11.jpg'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

# 显示结果
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='./simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')




import insightface_paddle as face
import logging
logging.basicConfig(level=logging.INFO)

parser = face.parser()
args = parser.parse_args()
args.build_index = "./demo/friends/index.bin"
args.img_dir = "./demo/friends/gallery"
args.label = "./demo/friends/gallery/label.txt"
predictor = face.InsightFace(args)
predictor.build_index()


parser = face.parser()
args = parser.parse_args()

args.det = True
args.output = "./output"
input_path = "./demo/friends/query/friends1.jpg"

predictor = face.InsightFace(args)
res = predictor.predict(input_path)
print(next(res))



parser = face.parser()
args = parser.parse_args()

args.rec = True
args.index = "./demo/friends/index.bin"
input_path = "./demo/friends/query/Rachel.png"

predictor = face.InsightFace(args)
res = predictor.predict(input_path, print_info=True)
print(next(res))



'''
from ultralytics import YOLO
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)
results = model("https://ultralytics.com/images/bus.jpg")
print(results)
'''
